package com.ruoyi.web.controller.cj;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.dto.CodeDTO;
import com.ruoyi.system.domain.dto.ImportDTO;
import com.ruoyi.system.domain.dto.RechargeDTO;
import com.ruoyi.system.domain.dto.WebInfoDTO;
import com.ruoyi.system.service.IMemberCodeService;
import com.ruoyi.system.service.IRechargeService;
import com.ruoyi.system.service.IShopNoticeService;
import com.ruoyi.system.service.ISlideshowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author yd
 * @date 2020/10/24 18:55
 * @remark
 */
@RestController
@RequestMapping("/newJob/select")
public class NewJobController {

    @Autowired
    private IRechargeService iRechargeService;
    @Autowired
    private IMemberCodeService iMemberCodeService;
    @Autowired
    private ISlideshowService iSlideshowService;
    @Autowired
    private IShopNoticeService iShopNoticeService;

    /**
     *  页面数据
     */
    @RequestMapping("/webInfo")
    public AjaxResult webInfo(){

        Long shopId = 1L;

        WebInfoDTO webInfo = new WebInfoDTO();

        //充值排名前三
        List<RechargeDTO> totalList = iRechargeService.totalList(shopId);

        webInfo.setRechargeList(totalList);
        //当月充值排名
        List<RechargeDTO> rechargeList = iRechargeService.rechargeList(shopId);

        webInfo.setMonthList(rechargeList);
        //总额度
        BigDecimal totalMoney = iRechargeService.totalMoney(shopId);
        webInfo.setTotalMoney(totalMoney);
        //码数排行榜
        List<CodeDTO> codeList = iMemberCodeService.codeList(shopId);

        webInfo.setCodeList(codeList);

        return AjaxResult.success(webInfo);

    }
    /**
     *  轮播图
     */
    @GetMapping("/slideshow")
    public AjaxResult slideshow(){

        return iSlideshowService.slideshow();

    }

    /**
     * 公告
     */
    @GetMapping("/notice")
    public AjaxResult notice(){

        return iShopNoticeService.notice();

    }

    /**
     * 导入
     */
    @PostMapping("/import")
    public AjaxResult importData(@RequestParam("file") MultipartFile file) throws Exception {

        if (file == null){

            return AjaxResult.error();
        }

        ExcelUtil<ImportDTO> util = new ExcelUtil<ImportDTO>(ImportDTO.class);
        List<ImportDTO> rechargeList = util.importExcel(file.getInputStream());
        String message = iRechargeService.importRecharge(rechargeList);

        return AjaxResult.success(message);

    }


}
